﻿@page "/Wms/BuyReturnOutWarehouse/Details"
@using nERP.ViewModel.Wms.BuyReturnOutWarehouseVMs
@using nERP.Model.Wms
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Tab IsBorderCard="true">
            <TabItem Text="@WtmBlazor.Localizer["_Admin.BasicInfo"]">
                <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
                    <Display @bind-Value="@Model.Entity.BuyReturnOutWarehouseCode" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.BuyReturnId" ShowLabel="true" Lookup="AllBuyReturns" />
                    <Display @bind-Value="@Model.Entity.BuyId" ShowLabel="true" Lookup="AllBuys" />
                    <Display @bind-Value="@Model.Entity.SupplierId" ShowLabel="true" Lookup="AllSuppliers" />
                    <Display @bind-Value="@Model.Entity.InvoicesDate" ShowLabel="true" FormatString="yyyy-MM-dd" />
                    <Display @bind-Value="@Model.Entity.MakeUserId" ShowLabel="true" Lookup="AllMakeUsers" />
                    <Display @bind-Value="@Model.Entity.Status" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.Remark" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.CreateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
                    <Display @bind-Value="@Model.Entity.UpdateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
                    <Display @bind-Value="@Model.Entity.CreateBy" ShowLabel="true" />
                    <Display @bind-Value="@Model.Entity.UpdateBy" ShowLabel="true" />
                    <WTUploadImage @bind-Value="@Model.Entity.InvoicesImage" thumb-width="128" />
                </Row>
                <Divider Icon="fa-fw fa-solid fa-bookmark" Text="@WtmBlazor.Localizer["_Model._BuyReturnOutWarehouse._BuyReturnOutWarehouseDetail_BuyReturnOutWarehouse"]" Alignment="Alignment.Left" />


                <Table TItem="BuyReturnOutWarehouseDetail"
                       IsPagination="false"
                       IsStriped="true" IsBordered="true" IsMultipleSelect="false" @bind-Items="@BuyReturnOutWarehouseDetailBuyReturnOutWarehouseList3" ShowFooter="true"
                       ShowToolbar="false" ShowExtendButtons="false" ShowSkeleton="true">
                    <TableColumns>
                        <TableColumn @bind-Field="@context.Seq" Text="@WtmBlazor.Localizer["Page.序号"]" />
                        <TableColumn @bind-Field="@context.BuyId" Text="@WtmBlazor.Localizer["Page.采购订单"]" Lookup="detailAllBuys" />
                        <TableColumn @bind-Field="@context.BuyReturnOutWarehouseDetailCode" Text="@WtmBlazor.Localizer["Page.采购退货出库明细单号"]" Visible="false" />
                        <TableColumn @bind-Field="@context.BuyDetailId" Text="@WtmBlazor.Localizer["Page.采购明细"]" Lookup="detailAllBuyDetails" />
                        <TableColumn @bind-Field="@context.WarehouseId" Text="@WtmBlazor.Localizer["Page.仓库"]" Lookup="detailAllWarehouses" />
                        <TableColumn @bind-Field="@context.GoodsId" Text="@WtmBlazor.Localizer["Page.商品编号"]" />
                        <TableColumn @bind-Field="@context.GoodsName" Text="@WtmBlazor.Localizer["Page.商品名称"]" />
                        <TableColumn @bind-Field="@context.GoodsSpec" Text="@WtmBlazor.Localizer["Page.商品规格"]" />
                        <TableColumn @bind-Field="@context.GoodsUnit" Text="@WtmBlazor.Localizer["Page.计量单位"]" />
                        <TableColumn @bind-Field="@context.ReturnNumber" Text="@WtmBlazor.Localizer["Page.退货出库数量"]" FormatString="0.##" />
                        <TableColumn @bind-Field="@context.Remark" Text="@WtmBlazor.Localizer["_Admin.Remark"]" />
                        <TableColumn @bind-Field="@context.CreateTime" Text="@WtmBlazor.Localizer["_Admin.CreateTime"]" FormatString="yyyy-MM-dd HH:mm:ss" />
                        <TableColumn @bind-Field="@context.UpdateTime" Text="@WtmBlazor.Localizer["_Admin.UpdateTime"]" FormatString="yyyy-MM-dd HH:mm:ss" />
                        <TableColumn @bind-Field="@context.CreateBy" Text="@WtmBlazor.Localizer["_Admin.CreateBy"]" />
                        <TableColumn @bind-Field="@context.UpdateBy" Text="@WtmBlazor.Localizer["_Admin.UpdateBy"]" />
                    </TableColumns>

                    <FooterTemplate>
                        <tr style="background-color:gray; font-weight:600; text-align:center;">
                            <td colspan="8">合计：</td>
                            <td>@sumReturnNumber</td>
                        </tr>
                    </FooterTemplate>
                </Table>
            </TabItem>

            <TabItem Text="@WtmBlazor.Localizer["Page.审批信息"]">
                <WTApproveHistory Model="@Model" />
            </TabItem>

        </Tab>



        <div class="modal-footer table-modal-footer">
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private BuyReturnOutWarehouseVM Model = new BuyReturnOutWarehouseVM();
    private ValidateForm vform { get; set; }
    private string sumReturnNumber { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Wms/BuyReturnOutWarehouse/Edit", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllBuyReturns = new List<SelectedItem>();
    private List<SelectedItem> AllBuys = new List<SelectedItem>();
    private List<SelectedItem> AllSuppliers = new List<SelectedItem>();
    private List<SelectedItem> AllMakeUsers = new List<SelectedItem>();
    private IEnumerable<BuyReturnOutWarehouseDetail> BuyReturnOutWarehouseDetailBuyReturnOutWarehouseList3 { get; set; } = new List<BuyReturnOutWarehouseDetail>();
    private List<SelectedItem> detailAllBuys = new List<SelectedItem>();
    private List<SelectedItem> detailAllBuyDetails = new List<SelectedItem>();
    private List<SelectedItem> detailAllWarehouses = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllBuyReturns = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouse/GetBuyReturns");
        AllBuyReturns.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllBuys = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouse/GetBuys");
        AllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSuppliers = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouse/GetSuppliers");
        AllSuppliers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllMakeUsers = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouse/GetFrameworkUsers");
        AllMakeUsers.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<BuyReturnOutWarehouseVM>($"/api/Wms/BuyReturnOutWarehouse/{id}");
            Model = rv.Data;
        }
        BuyReturnOutWarehouseDetailBuyReturnOutWarehouseList3 = Model.Entity.BuyReturnOutWarehouseDetail_BuyReturnOutWarehouse;
        var Items = Model.Entity.BuyReturnOutWarehouseDetail_BuyReturnOutWarehouse;
        sumReturnNumber = Items.Any() ? Items.Sum(x => x.ReturnNumber)?.ToString("#0.####") : "0";

        detailAllBuys = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetBuys");
        detailAllBuys.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        detailAllBuyDetails = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetBuyDetails");
        detailAllBuyDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        detailAllWarehouses = await WtmBlazor.Api.CallItemsApi("/api/Wms/BuyReturnOutWarehouseDetail/GetWarehouses");
        detailAllWarehouses.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });

        await base.OnInitializedAsync();
    }
}
